#########################################
#Getting data, params, etc. from BLP ====
#########################################
library(HeadR)
#
BLP <- fread("Data/BLP99/blp_1999_data.csv")
fwrite(BLP[,.(car_ids=car_id,domestic=domestic)],"Data/BLP99/domestic.csv")
#duplicates(BLP,by.vars=c("car_id")) #0 dups, 2217 obs 
#car_id is the unique identifier 
BLP[,firm_ab := substr(model_id,1,2)]
BLP[year==90,lapply(.SD,uniqueN),.SDcols =c("model_id","car_id","firm_id","firm_ab")]
setnames(BLP,old=c("model_id","firm_id","price","share","quantity"),new=c("m","f","p","s","q"))
BLP[, year := year+1900]
BLP[, n := 1]
BLP[, i := domestic]
BLP <- BLP[,.(year,m,f,p,s,q,const,hpwt,air,mpd,space,i,n)]
#
param <- fread("Data/BLP99/published_param.csv") # BLP1995 parameters
#
param[, xvar := st_right(param_name,"_")]
alpha <- param[param_name=="alpha_price"]$pub_param
b.means <- param[param_name %like% "demand"]$pub_param
names(b.means) <- param[param_name %like% "demand"]$xvar
b.sds <- param[param_name %like% "sigma"]$pub_param
names(b.sds) <- param[param_name %like% "sigma"]$xvar
y.mn <- fread("Data/BLP99/meanincome.csv")
y.mn[, year := V1+1900]
y.sd <- fread("Data/BLP99/sdincome.csv")$V1
